<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<div id="pagination">
    <c:choose>
        <c:when test="${nbpages<=30}">
            <%-- Lien précédent --%>
            <c:if test="${page != 1}">
                <a href="<c:url value="/ctrl/?action=cata&page=${page - 1}"/>"><-|</a>
            </c:if>

            <%--For displaying Page numbers.
            The when condition does not display a link for the current page--%>
            <c:forEach begin="1" end="${nbpages}" var="i">
                <c:choose>
                    <c:when test="${page eq i}">
                        - ${i} - 
                    </c:when>
                    <c:otherwise>
                        <a href="<c:url value="/ctrl/?action=cata&page=${i}"/>">${i}</a> 
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <%-- Lien suivant --%>
            <c:if test="${page lt nbpages}">
                <a href="<c:url value="/ctrl/?action=cata&page=${page + 1}"/>">|-></a>
            </c:if>
        </c:when>
        <c:otherwise>
            <%-- Lien précédent --%>
            <c:if test="${page != 1}">
                <a href="<c:url value="/ctrl/?action=cata&page=${page - 1}"/>"><-|</a>
            </c:if>

            <%--For displaying Page numbers.
            The when condition does not display a link for the current page--%>
            <c:forEach begin="${page}" end="${page+10}" var="i">
                <c:choose>
                    <c:when test="${page eq i}">
                        - ${i} - 
                    </c:when>
                    <c:otherwise>
                        <a href="<c:url value="/ctrl/?action=cata&page=${i}"/>">${i}</a> 
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            
               <%-- ... <a href="<c:url value="/ctrl/?action=cata&page=${page+1}"/>">${page+1}</a> ...  
            
            <c:forEach begin="${nbpages-5}" end="${nbpages}" var="i">
                <c:choose>
                    <c:when test="${page eq i}">
                        - ${i} - 
                    </c:when>
                    <c:otherwise>
                        <a href="<c:url value="/ctrl/?action=cata&page=${i}"/>">${i}</a> 
                    </c:otherwise>
                </c:choose>
            </c:forEach>--%>

            <%-- Lien suivant --%>
            <c:if test="${page lt nbpages}">
                <a href="<c:url value="/ctrl/?action=cata&page=${page + 1}"/>">|-></a>
            </c:if>
        </c:otherwise>

    </c:choose>    

</div>